<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Backup one database to another database</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="class.sqlite3.html">« SQLite3</a></li>
      <li style="float: right;"><a href="sqlite3.busytimeout.html">SQLite3::busyTimeout »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.sqlite3.html">SQLite3</a></li>
    <li>Backup one database to another database</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="sqlite3.backup" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">SQLite3::backup</h1>
  <p class="verinfo">(PHP 7 &gt;= 7.4.0, PHP 8)</p><p class="refpurpose"><span class="refname">SQLite3::backup</span> &mdash; <span class="dc-title">Backup one database to another database</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-sqlite3.backup-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>SQLite3::backup</strong></span>(<span class="methodparam"><span class="type"><a href="class.sqlite3.html" class="type SQLite3">SQLite3</a></span> <code class="parameter">$destination</code></span>, <span class="methodparam"><span class="type">string</span> <code class="parameter">$sourceDatabase</code><span class="initializer"> = &quot;main&quot;</span></span>, <span class="methodparam"><span class="type">string</span> <code class="parameter">$destinationDatabase</code><span class="initializer"> = &quot;main&quot;</span></span>): <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   <span class="methodname"><strong>SQLite3::backup()</strong></span> copies the contents of one database
   into another, overwriting the contents of the destination database.
   It is useful either for creating backups of databases
   or for copying in-memory databases to or from persistent files.
  </p>
  <div class="tip"><strong class="tip">小技巧</strong>
   <p class="para">
    As of SQLite 3.27.0 (2019-02-07), it is also possible to use the statement
    <code class="literal">VACUUM INTO &#039;file.db&#039;;</code> to backup the database to a new file.
   </p>
  </div>
 </div>


 <div class="refsect1 parameters" id="refsect1-sqlite3.backup-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt>
<code class="parameter">destination</code></dt>

    <dd>

     <p class="para">
      A database connection opened with <span class="methodname"><a href="sqlite3.open.html" class="methodname">SQLite3::open()</a></span>.
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">sourceDatabase</code></dt>

    <dd>

     <p class="para">
      The database name is <code class="literal">&quot;main&quot;</code> for the main database,
      <code class="literal">&quot;temp&quot;</code> for the temporary database,
      or the name specified after the <code class="literal">AS</code> keyword
      in an <code class="literal">ATTACH</code> statement for an attached database.
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">destinationDatabase</code></dt>

    <dd>

     <p class="para">
      Analogous to <code class="parameter">sourceDatabase</code>
      but for the <code class="parameter">destination</code>.
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-sqlite3.backup-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>true</code></strong>， 或者在失败时返回 <strong><code>false</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-sqlite3.backup-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="sqlite3.backup.example.basic">
   <p><strong>示例 #1 Backup an existing database</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;$conn&nbsp;is&nbsp;a&nbsp;connection&nbsp;to&nbsp;an&nbsp;already&nbsp;opened&nbsp;sqlite3&nbsp;database<br /><br /></span><span style="color: #0000BB">$backup&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SQLite3</span><span style="color: #007700">(</span><span style="color: #DD0000">'backup.sqlite'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$conn</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">backup</span><span style="color: #007700">(</span><span style="color: #0000BB">$backup</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
 </div>


</div></div></div></body></html>